#include "settingsdlg.h"

SettingsDlg::SettingsDlg(QVector<double> *s)
    :ui(new Ui::setDialog)
{
    ui->setupUi(this);
    this->sets=s;

    connect(ui->edt_iterNum,SIGNAL(textEdited(const QString &)),this,SLOT(updateArg()));
    connect(ui->edt_tInit,SIGNAL(textEdited(const QString &)),this,SLOT(updateArg()));
    connect(ui->edt_tFinal,SIGNAL(textEdited(const QString &)),this,SLOT(updateArg()));
    connect(ui->edt_a,SIGNAL(textEdited(const QString &)),this,SLOT(updateArg()));

    ui->edt_iterNum->setValidator(new QIntValidator(1,500,this));
    ui->edt_tInit->setValidator(new QDoubleValidator(1,1000,2,this));
    ui->edt_tFinal->setValidator(new QDoubleValidator(0.1,1,2,this));
    ui->edt_a->setValidator(new QDoubleValidator(0.9,0.99,3,this));

    rePrintArg();
}

SettingsDlg::~SettingsDlg()
{

}

void SettingsDlg::rePrintArg()
{
    ui->edt_iterNum->setText(QString::number(sets->at(0)));
    ui->edt_tInit->setText(QString::number(sets->at(1)));
    ui->edt_tFinal->setText(QString::number(sets->at(2)));
    ui->edt_a->setText(QString::number(sets->at(3)));
}

void SettingsDlg::updateArg()
{
    if(ui->edt_tFinal->text().toDouble()==ui->edt_tInit->text().toDouble()){
        QMessageBox::warning(this,"Warn","初始温度和结束温度不应当相同");
    }
    sets->clear();
    sets->push_back(ui->edt_iterNum->text().toDouble());
    sets->push_back(ui->edt_tInit->text().toDouble());
    sets->push_back(ui->edt_tFinal->text().toDouble());
    sets->push_back(ui->edt_a->text().toDouble());
}
